package nrd;

import static org.junit.Assert.assertTrue;
import robocode.control.testing.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that TheOrangeRobot
 * generally beats Crazy.
 * 
 * @author Nathan Dorman
 * 
 */
public class TestRobotVersusCrazy extends RobotTestBed {

  /**
   * Specifies that Crazy and TheOrangeRobot are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Crazy,nrd.TheOrangeRobot";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * The actual test, which asserts that TheOrangeRobot has won seven of ten rounds against Crazy.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] battleResults = event.getIndexedResults();
    // Sanity check that results[1] is TheOrangeRobot (not strictly necessary, but illustrative).
    BattleResults TheOrangeRobotResults = battleResults[1];

    boolean winsMajority = false;
    if (TheOrangeRobotResults.getFirsts() >= getNumRounds() - 3) {
      winsMajority = true;
    }
    // Check to make sure TheOrangeRobot most rounds.
    assertTrue("TheOrangeRobot wins atleast 7 of 10 times.", winsMajority);
  }
}